<?php
/**
 * Created by PhpStorm.
 * User: 李壮壮
 * Date: 2020-3-26
 * Time: 19:16
 */

namespace App\Http\Controllers\Home;


use App\Http\Controllers\Controller;

/**
 * Class AbsController
 * 基础控制器
 * @package App\Http\Controllers\Home
 */
class AbsController extends Controller
{
    /**
     * 返回成功的信息
     * @param array $data Array |string
     * @param string $msg
     * @param string $type
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
     */
    public function success($data=[],$msg='',$type='success')
    {

        return response([
            'data'=>$data,
            'msg'=>$msg,
            'type'=>$type
        ]);
    }

    /**
     * @param array $data
     * @param string $msg
     * @param string $type
     * @param $code
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
     */
    public function error($code,$msg='', $data=[],$type='error')
    {
        return response([
            'data'=>$data,
            'msg'=>$msg,
            'type'=>$type
        ],$code);
    }
}
